package com.jin.webvideo.base.util;

import java.io.InputStream;
import java.util.*;

/**
 * @ClassName ObjectsUtil
 * @description:
 * @author: biao532
 * @create: 2023-11-24 00:19
 * @Version 1.0
 **/
public class ObjectsUtil {
    /**
     * 推荐使用空对象替代null，保证空对象全局唯一不可变
     *
     * @author biao532
     * @date 2023/12/05 10:04
     **/
    public class Empty {
        public static final List LIST = Collections.unmodifiableList(new ArrayList<>(0));
        public static final Set SET = Collections.unmodifiableSet(new HashSet<>(0));
        public static final Map MAP = Collections.EMPTY_MAP;
        public static final String STRING = "";
        public static final InputStream INPUTSTREAM = InputStream.nullInputStream();
        public static final String[] STRINGS = new String[0];
        public static final int[] INTS = new int[0];
        public static final byte[] BYTES = new byte[0];
    }
    @FunctionalInterface
    public interface Converter<T, V> {
        V convert(T t);
    }
    public static <T, V> V convert(T data, Converter<T, V> converter) {
        return converter.convert(data);
    }

    public static <T> T getOrDefault(T chk, T data) {
        if (chk == null) {
            return data;
        }
        return chk;
    }

    public static boolean safeEquals(Object obj, Object obj2) {
        if (obj == obj2) {
            return true;
        }
        if (obj == null) {
            return obj2 == null;
        }
        return obj.equals(obj);
    }
}
